package com.dshore.messagecenter.controller.technology;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.dshore.messagecenter.controller.basedata.BaseController;
import com.dshore.messagecenter.model.technology.R;
import com.dshore.messagecenter.service.technology.EmailService;
import com.dshore.messagecenter.service.technology.ShortMessageService;

@Controller
@RequestMapping("/index")
public class EmailController extends BaseController{
	@Autowired
	private EmailService emailService;
	@Autowired
	private ShortMessageService shortMessageService;
	
	//发送邮件页面
	@RequestMapping("/toEmail")
	public ModelAndView IntoChangeStyle() {
		ModelAndView mv=new ModelAndView("email");
		mv.setViewName("technology/email");
		return mv;
	}	
	
	//发送邮件
	@RequestMapping(method = RequestMethod.POST, value ="/sendEmail")
	@ResponseBody
	public String sendEmail(String text) {
		emailService.sendEmail(text);
		return null;
	}
	
	//发送短信
	@RequestMapping(method = RequestMethod.POST, value ="/sendMessage")
	@ResponseBody
	public String sendMessage(String phone) {
		Map<String, Object> params=new HashMap<>();
		params.put("phone", phone);
		R r=shortMessageService.getAuthCode(params);
		System.out.println("发送:"+r);
		String authCode=r.get("AuthCode").toString();
		
		Map<String,Object> maps1=new HashMap<>();
        maps1.put("phone",phone);
        maps1.put("authCode",authCode);
		R r1=shortMessageService.checkAuthCode(maps1);
		System.out.println("验证:"+r1);
		
		return null;
	}
	
	
}
